<template>
  <div class="home">
    <el-card style="width: 600px;height: 150px;margin: 0 auto;
    background-color: rgba(255,255,255,0.3)">

      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

        <el-form-item label="车牌号" prop="carId">
          <el-input  v-model="ruleForm.carId"></el-input>
        </el-form-item>
        <el-form-item style="position: relative;right: 25px">
          <el-button type="primary" @click="add()">添加</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<style>
body {
  text-align: center;
  background-image: url("../assets/imgs/background.jpg");
  margin: 0; /*去掉自带外边距*/
  background-size: cover; /*cove  把背景图片设置为封面  设置之后  背景图片 不会随着浏览器缩放而缩放 会自动填充 */
  background-repeat: no-repeat; /*背景图片不重复*/
}

h1 {
  font-size: 72px;
  color: #0096dc;
  margin-bottom: 0;
}

h2 {
  font-size: 32px;
  color: #0096dc;
  margin-bottom: 0;
}
</style>
<script>
export default {
  data() {
    return {
      ruleForm: {
        cardId: '',
        carId: '',
      },
      rules: {
        carId: [
          {required: true, message: '输入车牌号', trigger: 'blur'},
          {min: 7, max: 7, message: '输入七位车牌号', trigger: 'blur'}
        ],
      }
    };
  },
  methods: {
    add(){
      this.ruleForm.cardId =  localStorage.getItem('cardId')
      let url = 'http://localhost:8080/car/addNewCar'
      console.log(this.ruleForm)
      this.axios.post(url, this.ruleForm).then((response) => {
        let responseBody = response.data;
        this.ruleForm.user =responseBody.data;
        if (responseBody.code == 200) {
          this.$message({
            showClose: true,
            message: '添加成功！',
            type: 'success'
          });
          this.$router.push('/UserIndex');
        } else if (responseBody.code == 404) {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        } else if (responseBody.code == 400) {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        }
      })
    }
  }
}

</script>
